<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="cn.java71.dao.*,cn.java71.entity.*,cn.java71.util.*" %>
<%@ page import="cn.java71.service.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Date" %>
<html>
<head>
    <title>显示首页的学生</title>
    <script src="js/jquery-3.4.1.min.js"></script>

</head>
<body>
<%--<%
    out.print(session.getId()+"<br/>");
    out.print(session.getLastAccessedTime()+"<br/>");
    out.print(session.getMaxInactiveInterval()+"<br/>");
    //String name=(String)session.getAttribute("LOGIN_USER");
%>--%>
<%--<h1>欢迎你，<%=name%></h1>--%>
<%--<%@include file="checkLogin.jsp"%>--%>

<%
    int p=1;
    try {
        p = Integer.parseInt(request.getParameter("p"));
    }catch (Exception e){}
    int pageSize=20;
    String sname=request.getParameter("sname");
    sname=StrUtil.toStr(sname);
    String qq=StrUtil.toStr(request.getParameter("qq"));
    String telephone=StrUtil.toStr(request.getParameter("telephone"));
    String startdate=StrUtil.toStr(request.getParameter("startdate"));
    String enddate=StrUtil.toStr(request.getParameter("enddate"));
    Date start=StrUtil.toDate(startdate);
    Date end=StrUtil.toDate(enddate);
    StudentService studentService=new StudentService();
    Page<Student> students = studentService.search(p, pageSize, sname, start, end);

%>
<form action="students.jsp" id="searchForm">
    <input type="hidden" name="p" id="p" value="1"/>
    <input type="search" id="sname" name="sname" value="<%=sname%>" placeholder="姓名"/>
    <input type="search" id="telephone" name="telephone" value="<%=telephone%>" placeholder="telephone"/>
    <input type="search" id="qq" name="qq" value="<%=qq%>" placeholder="qq"/>
    <input type="date" id="startdate" name="startdate" value="<%=startdate%>" placeholder="入学时间的起点"/>
    <input type="date" id="enddate" name="enddate" value="<%=enddate%>" placeholder="入学时间的终点"/>
    <input type="submit" value="查找"/>
</form>
<%--<h1>
    <%
        out.print(",当前时间:"+request.getAttribute("loginTime"));
        out.print("，当前用户:"+request.getParameter("userName"));
    %>
</h1>--%>
<table border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>手机号</th>
        <th>入学日期</th>
        <th>年级</th>
        <th>操作</th>
    </tr>
    <%
        for(Student stu:students.getDatas()){
    %>
    <tr>
        <td><%=stu.getStuno()%></td>
        <td><%=stu.getSname()%></td>
        <td><%=stu.getTelephone()%></td>
        <td><%=stu.getEnterdate()%></td>
        <td><%=stu.getGname()%></td>
        <td>
            <a onclick="return confirm('真的要删除<%=stu.getSname()%>？')"
               href="delStudent.jsp?stuno=<%=stu.getStuno()%>">删除</a>
            <a href="studentUpdate.jsp?stuno=<%=stu.getStuno()%>">修改</a>
        </td>
    </tr>

    <%}%>
</table>
</ul>
<p align="center" id="pager">
    <a href="students.jsp?p=1&sname=<%=sname%>" id="first">首页</a>
    <% if(students.getPageNo()>1){%>
    <a href="students.jsp?p=<%=p-1%>&sname=<%=sname%>" id="prev">上一页</a>
    <%}%>
    <input type="number" min="1" max="<%=students.getTotalPages()%>" name="p" id="jump" size="4" value="<%=p%>" style="width: 50px"/>
    <%
        if(students.getPageNo()<students.getTotalPages()){
    %>
    <a href="students.jsp?p=<%=p+1%>&sname=<%=sname%>" id="next">下一页</a>
    <%}%>
    <a href="students.jsp?p=<%=students.getTotalPages()%>&sname=<%=sname%>" id="last">末页</a>
</p>
<script>
    $(function () {

        $("#jump").keypress(function (event) {
            //alert($(this).attr("max"));
            if(event.keyCode==13){
                if(parseInt($(this).val())>parseInt($(this).attr("max"))){
                    alert("超了");
                    return false;
                }
                window.location.href="students.jsp?p="+$(this).val()+"&sname="+$("#sname").val();
            }
        }).blur(function () {
            if(parseInt($(this).val())>parseInt($(this).attr("max"))){
                alert("超了");
                return false;
            }

            window.location.href="students.jsp?p="+$(this).val()+"&sname="+$("#sname").val();
        });

        //点击上一个，下一个
        var curr=<%=students.getPageNo()%>;
        $("#pager a#prev").click(function () {
            curr--;
            $("form#searchForm :hidden[name=p]").val(curr);
            $("form#searchForm").submit();
            return false;
        });
        $("#pager a#next").click(function () {
            curr++;
            $("form#searchForm :hidden[name=p]").val(curr);
            $("form#searchForm").submit();
            return false;
        });
    });
</script>
</body>
</html>
